package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.TenantFrom;
import com.moss.cloud.base.api.model.param.TenantPageParam;
import com.moss.cloud.base.biz.service.ISysTenantService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(ServiceList.BASE + "/sysTenant")
public class SysTenantController {
    private ISysTenantService sysTenantService;

    public SysTenantController(ISysTenantService sysTenantService) {
        this.sysTenantService = sysTenantService;
    }

    /**
     * 登录租户信息
     *
     * @return
     */
    @PostMapping("/tenantInfo")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "登录租户信息")
    public Result<?> tenantInfo() {
        return Result.success(sysTenantService.tenantInfo());
    }
    /**
     * 租户ID查询租户基本信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/byTenantId")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "租户ID查询租户基本信息")
    public Result<?> byTenantId(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(sysTenantService.byTenantId(baseFrom.getId()));
    }

    /**
     * 用户ID查询租户基本信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/tenantInfoByUserId")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "用户ID查询租户基本信息")
    public Result<?> tenantInfoByUserId(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(sysTenantService.tenantInfoByUserId(baseFrom.getId()));
    }

    /**
     * 租户分页查询
     *
     * @return
     */
    @PostMapping("/tenantPage")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "租户分页查询")
    public Result<?> tenantPage(@RequestBody TenantPageParam tenantPageParam) {
        return Result.success(sysTenantService.tenantPage(tenantPageParam));
    }

    /**
     * 删除租户信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeTenant")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除租户信息")
    public Result<?> removeTenant(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysTenantService.removeTenant(baseFrom));
    }

    /**
     * 启用，停用租户
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/disabledTenant")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "启用，停用租户")
    public Result<?> disabledTenant(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysTenantService.disabledTenant(baseFrom));
    }

    /**
     * 新增租户
     *
     * @param tenantFrom
     * @return
     */
    @PostMapping("/saveTenant")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增租户")
    public Result<?> saveTenant(@RequestBody @Validated TenantFrom tenantFrom){
        return Result.success(sysTenantService.saveTenant(tenantFrom));
    }

    /**
     * 更新租户信息
     *
     * @param tenantFrom
     * @return
     */
    @PostMapping("/updateTenant")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "更新租户信息")
    public Result<?> updateTenant(@RequestBody @Validated TenantFrom tenantFrom){
        return Result.success(sysTenantService.updateTenant(tenantFrom));
    }
}
